<?php
include("connection.php");
include("header.php");
//session_start();
//$result=mysql_query("SELECT * FROM users WHERE id='".$_SESSION['userid']."' ")
//or die(mysql_error());
//$row=mysql_fetch_array($result);
 
 //$fname=$row["fname"];
// $lname=$row["lname"];



//echo "welcome  ".$fname." ".$lname."";
//echo "  <a href='logout.php'>logout</a>";

?>
<?php
if($_GET['action']=="booking")
{
	$eventid=$_GET['id'];
	$userid = $_SESSION['userid'];
	if($userid=="")
	{
		header("location:login.php");
		exit;
	} else {
		
		$result=mysql_query("SELECT * FROM booking WHERE userid='".$userid."' AND eventid='".$eventid."' ORDER BY bookingid DESC ")or die(mysql_error());
		$num = mysql_num_rows($result);
		
		if($num)
				{
			echo '<font color="#FF0000" size="3" >you have already booked for this workshop</font>';
			$row=mysql_fetch_array($result);
	echo " Your Booking id is: <font color='#006633' size='4' >".$row['bookingid']."</font>";
				} 
		else
			{
	mysql_query("INSERT INTO booking (eventid, userid) VALUES ('$eventid','$userid') ") or die(mysql_error());
	
	$result=mysql_query("SELECT * FROM booking WHERE userid='".$userid."' AND eventid='".$eventid."' ORDER BY bookingid DESC ")or die(mysql_error());
	$row=mysql_fetch_array($result);
	echo "<font color='#006633' size='4' >Booked successfully! Your Booking id is".$row['bookingid']."</font>";
	
			}
	
	
	
		}
	
	}
	
	$result1=mysql_query("SELECT * FROM event GROUP BY type ASC");
	while($row1 = mysql_fetch_array($result1))
	{
	$ev_type= $row1["type"];
	echo "<h4>".$ev_type."</h4>";
	$result=mysql_query("SELECT * FROM event WHERE type='".$ev_type."'");
	$total = mysql_num_rows($result);
	$i=0;
	 echo'<table width="650" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFD8B0">
  <tr>
    <td><h5>EVENT NAME</h5></td>
    <td><h5>VENUE</h5></td>
    <td><h5>DATE</h5></td>
    <td><h5>START TIME</h5></td>
    <td><h5>END TIME</h5></td>
    <td><h5>GUEST</h5></td>
    <td><h5>DES</h5></td>
    
  </tr>';


	while($i< $total)
	{
	$row=mysql_fetch_array($result);
	
	  $eventname = $row['eventname'];
	  $venue=$row["venue"];
	  $date=$row["date"];
	  $starttime=$row["starttime"];
	  $endtime=$row["endtime"];
	  $maixumnumber=$row["maxnum"];
	  $guest=$row["guest"];
	  $des=$row["des"];
	  $payment=$row["payment"];
	  //$type=$row["type"];
	
	
	echo"
	<tr>
	<td>".$eventname."</td>
	<td>".$venue."</td>
	<td>".$date."</td>
	<td>".$starttime."</td>
	<td>".$endtime."</td>
	<td>".$guest."</td>
	<td>".$des."</td>
	
	<td><a href='?action=booking&id=".$row["id"]."'><img src='images/book.jpg' border='0'/><a/>   </td>
	</tr>";
	
	$i++;
	}
	echo "</table>";
	}
	include("footer.php");
	
	?>